package com.jtemimal.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FileCompletion {
    public static List<String> getFileCompletions(String path) {
        List<String> suggestions = new ArrayList<>();
        
        try {
            File directory;
            String prefix = "";
            
            if (path.isEmpty()) {
                directory = new File(".");
            } else {
                File file = new File(path);
                if (file.isDirectory()) {
                    directory = file;
                } else {
                    directory = file.getParentFile();
                    prefix = file.getName();
                }
            }
            
            if (directory != null && directory.exists()) {
                File[] files = directory.listFiles();
                if (files != null) {
                    for (File f : files) {
                        String name = f.getName();
                        if (name.startsWith(prefix)) {
                            if (f.isDirectory()) {
                                suggestions.add(name + "/");
                            } else {
                                suggestions.add(name);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return suggestions;
    }
} 